home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Arashi 1.1 / Game Source / mtz / mtz src / gestaltCalls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-21  |  4.5 KB  |  167 lines  |  [TEXT/KAHL]

  1. #include <GestaltEQU.h>
  2. #include <stdio.h>
  3.  
  4. #define BOTH
  5. /* #define DEBUG_GESTALT */
  6.  
  7. ProcPtr oldSAVRProc;
  8. Handle    savrHandle;
  9. Handle    savrDumHandle;
  10. ProcPtr oldASHIProc;
  11. Handle    ASHIHandle;
  12. Handle    ASHIDumHandle;
  13.  
  14. void ReplaceASHI(){
  15.     ProcPtr    tempProc;
  16.     OSErr    myErr = 0;
  17.     long    response;
  18.     OSErr myReplaceErr = 0;
  19.     
  20.     /* if a selector was in place when ARASHI started, reinstall it                    */
  21.     if(ASHIHandle && oldASHIProc){
  22.         if(myErr = ReplaceGestalt('ASHI',(ProcPtr)oldASHIProc, &tempProc)){
  23.             ParamText("\pAn error has occurred in removing the ASHI Gestalt selector.  You may have to reboot before restarting ARASHI.",nil,nil,nil);
  24.             Alert(131,0);
  25.         }
  26. #ifdef DEBUG_GESTALT
  27.         else{
  28.                 ParamText("\pThe old ASHI Gestalt selector has been reinstalled. ",nil,nil,nil);
  29.                 Alert(131,0);
  30.             } 
  31. #endif
  32.     }
  33.     /* else install a dummy selector, or better remove it altogether if possible    */
  34.     /* not possible yet, so replace it with the dummy one #131                        */
  35.     else{
  36.         if(ASHIDumHandle = GetResource('GDEF',131)){
  37.             DetachResource(ASHIDumHandle);
  38.             if(myReplaceErr = ReplaceGestalt('ASHI', (ProcPtr)*ASHIDumHandle, &oldASHIProc)){
  39.                 DisposHandle(ASHIDumHandle);
  40.                 ASHIDumHandle = 0L;
  41.                 ParamText("\pAn error has occurred in removing the ASHI Gestalt selector.  You may have to reboot before restarting ARASHI. ",nil,nil,nil);
  42.                 Alert(131,0);
  43.             }
  44. #ifdef DEBUG_GESTALT            
  45.             else{
  46.                 ParamText("\pA dummy 0 ASHI Gestalt selector has been  installed. ",nil,nil,nil);
  47.                 Alert(131,0);
  48.             } 
  49. #endif
  50.         }
  51.     }
  52.     Gestalt('ASHI',&response);
  53. #ifdef DEBUG_GESTALT
  54.     if(response == 1)
  55.         ParamText("\pASHI returns a 1 when exiting.",nil,nil,nil);
  56.     else
  57.         ParamText("\pASHI returns a 0 when exiting.",nil,nil,nil);
  58.     Alert(131,0);
  59. #endif
  60.     DisposHandle(ASHIHandle);
  61. }
  62.  
  63. #ifdef BOTH
  64. /* ResetGestalt() will reset the Gestalt selectors to the way they were before         */
  65. /* starting.                                                                        */
  66. void ResetGestalt(){
  67.     ProcPtr    tempProc;
  68.     OSErr    myErr;
  69.     long    response;
  70. #ifdef BEEP    
  71.     if(Gestalt('SAVR',&response))
  72.         SysBeep(1);
  73.     if(response == 0x12)
  74.         SysBeep(1);
  75. #endif
  76.     /* if a selector was in place when ARASHI started, replace it                    */
  77.     if(savrHandle && oldSAVRProc){
  78.         if(myErr = ReplaceGestalt('SAVR',(ProcPtr)oldSAVRProc, &tempProc))
  79.                 Alert(130,0);
  80.     }
  81.     /* else install a dummy selector, or better remove it altogether if possible    */
  82.     /* not possible yet, so replace it with the dummy one #129                        */
  83.     else{
  84.         if(savrDumHandle = GetResource('GDEF',129)){
  85.             DetachResource(savrDumHandle);
  86.             if(ReplaceGestalt('SAVR', (ProcPtr)*savrDumHandle, &oldSAVRProc)){
  87.                 DisposHandle(savrDumHandle);
  88.                 savrDumHandle = 0L;
  89.                 ParamText("\pAn error has occurred in removing the ASHI Gestalt selector.  You may have to reboot before restarting ARASHI. ",nil,nil,nil);
  90.                 Alert(131,0);
  91.             }
  92.         }
  93.     }
  94.     DisposHandle(savrHandle);
  95. #ifdef BEEP    
  96.     if(Gestalt('SAVR',&response))
  97.         SysBeep(1);
  98.     if(response == 0)
  99.         SysBeep(1);
  100. #endif
  101. }
  102. #endif
  103.  
  104. int installASHI()
  105. {
  106.     
  107.     int    error = 0;
  108.     long    response;
  109.     OSErr    myErr;
  110.     OSErr     myNewErr = 0;
  111.     OSErr     myReplaceErr = 0;
  112.     
  113.     myErr = Gestalt('ASHI',&response);
  114.     if( (myErr == 0) && (response == 1)){  /* only one copy at a time please.. */
  115.         ParamText("\pOnly one copy of ARASHI may be active at a time.",nil,nil,nil);
  116.         Alert(131,0);
  117.         return 1;
  118.     }
  119.     else{
  120.         oldASHIProc = 0L;                        /* mark none installed so far */
  121.         if(ASHIHandle = GetResource('GDEF',130)){
  122.             DetachResource(ASHIHandle);
  123.             if(myNewErr = NewGestalt('ASHI',*ASHIHandle))
  124.                 if(myReplaceErr = ReplaceGestalt('ASHI', *ASHIHandle, &oldASHIProc)){
  125.                     DisposHandle(ASHIHandle);
  126.                     ASHIHandle = 0L;
  127.                     ParamText("\pAn error has occurred trying to install ARASHI.",nil,nil,nil);
  128.                     Alert(131,0);
  129.                     error = 1;
  130.                 }
  131.         }
  132.     }
  133.     return error;
  134. }
  135.  
  136. #ifdef BOTH
  137. /* DisableSuperclock will set the Gestalt selector 'savr'     */
  138. /* to indicate that a screen saver, such as afterdark,         */
  139. /* is enabled already, thus superclock will                    */
  140. /* not attempt to draw on the playing surface.                */
  141. void DisableSuperClock(){
  142.     
  143.     long    response = 0;
  144.     OSErr     myNewErr = 0;
  145.     OSErr     myReplaceErr = 0;
  146.     
  147.     oldSAVRProc = 0L;
  148.     if(savrHandle = GetResource('GDEF',128)){
  149.         DetachResource(savrHandle);
  150.         if(myNewErr = NewGestalt('SAVR',(ProcPtr)(*savrHandle) ))
  151.             if(myReplaceErr = ReplaceGestalt('SAVR',(ProcPtr)(*savrHandle), &oldSAVRProc)){
  152.                 DisposHandle(savrHandle);
  153.                 savrHandle = 0L;
  154.                 ParamText("\pAn error has occurred trying to re-activate Superclock",nil,nil,nil);
  155.                 Alert(131,0);
  156.             }
  157.     }
  158. #ifdef BEEP    
  159.     if(Gestalt('SAVR',&response))
  160.         SysBeep(1);
  161.     if(response == 0x12)
  162.         SysBeep(1);
  163. #endif
  164. }
  165. #endif
  166.  
  167.